/******************************************************************************
* File description: OpenFileOthersFileUpLoad.qml
* Function: 上传文件窗口
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-07
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Item {
    id: root

    /* property 定义开始 */

    // private
    property string _deviceType: "" // 设备类型
    property string _analyDeviceType: "3500XL" // 分析仪器设备类型
    property url _filePath: "" // 文件路径
    property var _analysisDeviceList: ["3500XL", "3500", "SeqStudio 24Flex", "3130XL", "3130"]
    property var _deviceList: ["7500", "7500线上", "鲲鹏", "Q5", "Q5英文版",
        "伯乐", "Design and Analysis-线下版"]

    // 信号
    signal sendDeviceType(string deviceType); // 发送设备类型
    signal selectFile(); // 选择文件
    signal cancel(); // 取消按钮
    signal submit(string uploadTableData, string analyDevice); // 确认按钮

    // c++槽函数
    Connections {
        target: othersFileUpload
    }

    /* property 定义结束 */

    Item {
        id: container
        anchors.fill: parent

        ColumnLayout {
            anchors.fill: parent
            spacing: 0

            // 内容
            Item {
                id: content
                Layout.fillWidth: true
                Layout.fillHeight: true
                Layout.topMargin: 40
                Layout.leftMargin: 20
                Layout.rightMargin: 20

                ColumnLayout {
                    anchors.fill: parent
                    spacing: 20

                    // 仪器文件
                    Item {
                        id: deviceFile
                        Layout.fillWidth: true
                        Layout.preferredHeight: 40

                        RowLayout {
                            anchors.fill: parent
                            spacing: 8

                            // 输入框
                            LabelTextInput {
                                id: deviceFileInput
                                Layout.fillWidth: true
                                Layout.fillHeight: true
                                inputWidth: width
                                inputHeight: height
                                labelText: "仪器文件"
                                placeholderText: "请选择文件"
                                inputText: _filePath
                                inputReadOnly: true // 只读模式
                                disabledBgColor: "transparent"
                                disabledFontColor: "#FF999999"

                                Component.onCompleted: {
                                    deviceFileInput.setLabelSize(analyDevice.getLabelSize()[0], undefined)
                                }
                            }

                            // 选择文件按钮
                            PureImgButton {
                                id: deviceFileSelector
                                Layout.preferredWidth: 120
                                Layout.preferredHeight: 40

                                pureText: "选择文件"
                                pureIconPath: "qrc:/icons/upload.svg"

                                onReleased: {
                                    root.selectFile(); // 选择数据
                                }
                            }
                        }
                    }

                    // 仪器
                    // 定量仪器
                    LabelComboBox {
                        id: deviceComboBox
                        Layout.fillWidth: true
                        Layout.preferredHeight: 40
                        comboBoxWidth: width
                        comboBoxHeight: height
                        boxFontHorAlign: Text.AlignLeft
                        comboBoxText: "定量仪器    "
                        model: _deviceList
                        onCurrentTextChanged: {
                            _deviceType = text
                            root.sendDeviceType(_deviceType) // 发送设备类型
                        }

                        Component.onCompleted: {
                            root.sendDeviceType(_deviceType) // 发送设备类型
                            deviceComboBox.setLabelSize(analyDevice.getLabelSize()[0], undefined)
                        }
                    }

                    // 分析仪器
                    LabelComboBox {
                        id: analyDevice
                        Layout.fillWidth: true
                        Layout.preferredHeight: 40
                        comboBoxWidth: width
                        comboBoxHeight: height
                        boxFontHorAlign: Text.AlignLeft
                        comboBoxText: "基因分析仪"
                        model: _analysisDeviceList
                        onCurrentTextChanged: {
                            root._analyDeviceType = text
                        }
                    }

                    // 表格
                    OpenFileOthersFileUpLoadTable {
                        id: uploadTable
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                    }
                }
            }

            CustomVerSpacerItem {}

            // 按钮
            Item {
                id: btnContainer
                Layout.fillWidth: true
                Layout.preferredHeight: 40
                Layout.bottomMargin: 40

                RowLayout {
                    anchors.fill: parent
                    spacing: 16

                    CustomHorSpacerItem {}

                    // 取消
                    PureImgButton {
                        id: cancelBtn
                        Layout.preferredWidth: 120
                        Layout.preferredHeight: 40
                        pureText: "取消"
                        pureIconWidth: 0

                        onReleased: {
                            root.cancel()
                        }
                    }

                    // 分析
                    PureImgButton {
                        id: submitBtn
                        Layout.preferredWidth: 120
                        Layout.preferredHeight: 40
                        pureIconWidth: 0
                        pureIconHeight: 0
                        pureBtnBorderWidth: 0
                        pureBtnColor: "#FF2F42CD"
                        pureFontColor: "#FFF"
                        pureHoveredFontColor: "#FFF"
                        pureText: "分析"

                        onReleased: {
                            // 表格返回数据
                            // var uploadTableData = JSON.stringify(uploadTable.returnTableSavedData())
                            // root.submit(uploadTableData, root._analyDeviceType)
                        }
                    }

                    CustomHorSpacerItem {}
                }
            }
        }
    }
}
